<template>
    <h2>
        修改页面
    </h2>
    <table class="table-bordered" border="1">
    <tr>
        <td>投资项目名称</td>
        <td><input type="text" v-model="info.I_Name" placeholder="请输入项目投资名称"></td>
    </tr>
    <tr>
        <td>投资总额度</td>
        <td><input type="text" v-model="info.I_Budget" placeholder="请输入投资总额度"></td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" value="修改" @click="UpdateInfo" class="btn btn-success">
        </td>
    </tr>
</table>
</template>
<script setup lang="ts">
import { useRoute,useRouter } from 'vue-router';
import { onMounted,ref } from 'vue';
import axios from 'axios';
const route = useRoute();
const router = useRouter();
var Iid=route.params.Iid
const info = ref(
    {
        I_Name: '',
        I_Budget: ''
    }
)


onMounted(() => {
    ShowInvestById()
})
const ShowInvestById=()=>{
    axios.get('https://localhost:44358/api/Invest/GetInvestById',
        {
            params:{
                Iid:route.params.Iid
            }
        }
    )
    .then(res=>{
        info.value.I_Name=res.data.I_Name
        info.value.I_Budget=res.data.I_Budget
    }).catch(err=>{
        console.log(err)
    })
}
const UpdateInfo=()=>{
    
    axios.post('https://localhost:44358/api/Invest/UpdateInvest',
        {
            I_Id:route.params.Iid,
            I_Name:info.value.I_Name,
            I_Budget:info.value.I_Budget
        }
    )
    .then(res=>{
        if(res.data==-1){
            alert("有人投资 修改失败")

        }
        else if(res.data>0){
            alert("修改成功")
            router.push('/ShowInvest')
        }else{
            alert("修改失败")
        }
    }).catch(err=>{
        console.log(err)
    })
}





</script>